FROM ubuntu:bionic

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

######
# Install common dependencies from packages. Versions here are either
# sufficient or irrelevant.
# WARNING: DO NOT PUT JAVA APPS HERE! Otherwise they will install default
# Ubuntu Java.  See Java section below!
######
RUN apt-get -q update \
    && apt-get -q install -y --no-install-recommends \
        build-essential \
        autoconf \
        automake \
        libtool \
        `cmake` \
        zlib1g-dev \
        pkg-config \
        libssl-dev \
        libssl1.0.0 \
        libsasl2-dev \
        bats \
        curl \
        sudo \
        git \
        python \
        python-dev \
        python-pip \
        python3 \
        python3-pip \
        nodejs \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN curl -L https://get.rvm.io | bash -s stable --autolibs=enabled && source ~/.profile
RUN pip install mock
RUN pip3 install mock

#######
# OpenJDK 8
#######
RUN apt-get -q update \
    && apt-get -q install -y --no-install-recommends openjdk-8-jdk \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-arm64

RUN apt-get -q update \
    &&	apt-get -q install -y maven \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN useradd -m -d /home/storm -s /bin/bash storm && adduser storm sudo
RUN echo "storm ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
USER storm
WORKDIR /home/storm

RUN curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.26.1/install.sh | bash && source ~/.bashrc

RUN mkdir -p ~/storm-results/

# docker build . -t liusheng2048/storm-aarch64:pre-build --build-arg prebuild=true
ARG prebuild=false
RUN if [ "$prebuild" = "true" ]; then git clone https://github.com/apache/storm \
    && cd storm \
    && mvn install -e -B 2>&1 |tee ~/storm-results/storm_build_test.log; fi

CMD if [ ! -d storm ]; then git clone https://github.com/apache/storm; fi \
    && cd storm \
    && mvn install -e -B -Dtar 2>&1 |tee ~/storm-results/storm_build_test.log
